package com.zjitc.controller;

import com.zjitc.model.CartItem;
import com.zjitc.model.Order;
import com.zjitc.model.Orderitem;
import com.zjitc.model.Product;
import com.zjitc.model.User;
import com.zjitc.service.OrderService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.InternalResourceView;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/19 15:48
 * @description:
 */

@Controller
public class UserOrder {
  @Autowired
  private OrderService orderService;
  private ModelAndView mv=new ModelAndView();
  @RequestMapping("/createOrder")
  public ModelAndView createOrder(HttpSession session){
      User user1= (User) session.getAttribute("user");
      Order order=new Order();
      order.setAddr(user1.getAddr());
      order.setPhone(user1.getPhone());
      order.setState(0);
      order.setOid(user1.getPhone());
      order.setTotal(100);
      List<Orderitem> orderitemList=new ArrayList<Orderitem>();
      order.setOrderitemList(orderitemList);
      orderService.addOrder(order);
      mv.addObject("order",order);
      mv.setView(new InternalResourceView("WEB-INF/user/order.jsp"));
      return mv;
  }
  @RequestMapping("/orderList")
  public ModelAndView orderList(){
      List<Orderitem> findOrderitem=orderService.findOrderitem();
      mv.addObject("findOrderitem",findOrderitem);
      mv.setView(new InternalResourceView("WEB-INF/user/orderList.jsp"));
      return mv;
  }
  @RequestMapping("/removerOrder")
  public ModelAndView removerOrder(@RequestParam("itemid")Integer itemid){
      orderService.remover(itemid);
      mv.setView(new InternalResourceView("/WEB-INF/user/orderList.jsp"));
      return mv;
  }





}
